<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
    <link rel="stylesheet" href="/static/admin/voucher.css?123">
</head>
<body>
<div class="layui-form layuimini-form">
    <!--奖品类型-->
    <input type="hidden" name="category" value="{$type}">
    <!--活动类型-->
    <input type="hidden" name="mark" value="{$mark}">
    <!--签到需要第几天的id-->
    <input type="hidden" name="active_id" value="{$active_id}">
    <div class="layui-form-item">
        <label class="layui-form-label required">奖品名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="required" lay-reqtext="奖品名称不能为空" placeholder="请输入奖品名称" value="" class="layui-input">
        </div>
    </div>
    {if condition="$type==3"}
    <div class="layui-form-item">
        <label class="layui-form-label">选择卡券</label>
        <div class="layui-input-block" style="display: flex">
            <button class="layui-btn" onclick="checkVoucher()">点击选择卡券</button>
            <input type="hidden" name="voucher_id" id="voucher_id">
            <input type="hidden" name="voucher_title" id="voucher_title">
            <div style="margin-left:10px;padding-top:10px;" id="voucherShow"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">卡券有效期（单位：天）</label>
        <div class="layui-input-block">
            <input type="number" name="validity_period" lay-verify="required" min='1' step="1" value="" class="layui-input">
        </div>
    </div>
    {/if}
    <div class="layui-form-item">
        <label class="layui-form-label required">奖励数量</label>
        <div class="layui-input-block">
            <input type="number" name="reward_num" lay-verify="required" step="1" min='1' value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">上架数量</label>
        <div class="layui-input-block">
            <input type="number" name="stock_num" lay-verify="required" min='1' step="1" value="" class="layui-input">
        </div>
    </div>
    {if condition="$mark!=4 and $mark!=2"}


    <div class="layui-form-item">
        <label class="layui-form-label required">单位</label>
        <div class="layui-input-block">
            <input type="text" name="unit" lay-verify="required" lay-reqtext="奖品单位不能为空" placeholder="请输入奖品单位" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">获奖概率</label>
        <div class="layui-input-block">
            <input type="number" name="reward_rate" lay-verify="required" min='0' max="1" step="0.01" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">单人中奖次数</label>
        <div class="layui-input-block">
            <input type="number" name="reward_times" lay-verify="required" min='0' step="1" value="" class="layui-input">
        </div>
    </div>
    {if condition="$type==5"}
    <div class="layui-form-item">
        <label class="layui-form-label required">价值</label>
        <div class="layui-input-block">
            <input type="number" name="worth" lay-verify="required" min='0' max="1" step="0.01" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">奖品说明</label>
        <div class="layui-input-block">
            <textarea name="detail" class="layui-textarea" lay-verify="required" placeholder="请输入奖品说明"></textarea>
        </div>
    </div>
    {/if}
    {/if}
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form','laydate'], function () {
        var form = layui.form,
            layer = layui.layer,
            laydate=layui.laydate,
            $ = layui.$;
        //监听提交
        form.on('submit(saveBtn)', function (data) {
            $.ajax({
                url: "/admin/Prize/create?action=create",
                type: 'post',
                async: true,
                data: data.field,
                dataType: 'json',
                success: function (res) {
                    if(res.status){
                        if(data.field.mark==1 || data.field.mark==2||data.field.mark==3){
                            parent.getsPrizeList("{$mark}");
                        }else{
                            parent.location.reload();
                        }

                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(iframeIndex);
                    }
                }
            });
            return false;
        });

    });

    /**
     * @context 卡券列表
     */
    var voucherOpen;
    function checkVoucher()
    {
        $.ajax({
            url: "/admin/Prize/getsPrizeVoucherList",
            type: 'post',
            async: true,
            data: {},
            dataType: 'json',
            success: function (res) {
                voucherOpen=layer.open({
                    type: 1 ,
                    title: "卡券列表",
                    area: ['800px', '500px'],
                    shade: 0.5,
                    maxmin: true,
                    content:res.data,
                    success:function(layero,index){
                        // 禁止回车键打开弹窗
                        $(":focus").blur();
                    }
                })
                return false;
            }
        });
    }

    /**
     * @context 选择卡券
     * @param id
     * @param title
     * @param price
     */
    function chooseVoucher(id,title,price)
    {
        $("#voucher_id").val(id);
        $("#voucher_title").val(title);
        $("#voucherShow").html(title+"    ￥"+price);
        layer.close(voucherOpen);
    }
</script>
</body>
</html>